package systeminfo

import (
	"fmt"
	"github.com/shirou/gopsutil/mem"
	"statuspage/utils"
	"strconv"
	"strings"
)

func GetRamStatus() Ram {
	virtualMemory, err := mem.VirtualMemory()
	if err != nil {
		return Ram{}
	}

	swapMemory, err := mem.SwapMemory()
	if err != nil {
		return Ram{}
	}

	memoryInfo := Ram{
		Totalram:  fmt.Sprintf("%.2f", utils.ConvertBytesToGB(virtualMemory.Total)),
		Freeram:   fmt.Sprintf("%.2f", utils.ConvertBytesToGB(virtualMemory.Available)),
		Totalswap: fmt.Sprintf("%.2f", utils.ConvertBytesToGB(swapMemory.Total)),
		Freeswap:  fmt.Sprintf("%.2f", utils.ConvertBytesToGB(swapMemory.Free)),
	}

	return memoryInfo
}
func getCount(s string) (v int) {
	temp := strings.Split(s, ":")[1]
	temp = strings.Trim(temp, "kB")
	temp = strings.Trim(temp, ":")
	temp = strings.Trim(temp, " ")
	v, err := strconv.Atoi(temp)
	if err != nil {
		fmt.Println(err)
	}
	return
}
